/**
 * 用户相关信息及token储存地
 * */
import { defineStore } from "pinia";
import router from "@/router";

export const userInfoStore = defineStore('user', {
 state: () => ({
  token: '',
  info: '',
  password: '',
  userId: ''
 }),

 getters: {
  getToken: (state) => state.token,
  getInfo: (state) => state.info,
  getPs: (state) => state.password,
  getUserId: (state) => state.userId,
 },

 // 存储修改
 actions: {

  handleToken(val) {
   // 当为空值时，则退出登录
   if (val) return this.token = val

   this.token = ''
   router.push('/login')
  },

  handleInfo(val) {
   this.info = val
  },

  handlePs(val) {
   this.password = val
  }

 },

 persist: {
  storage: sessionStorage,
  paths: ['token', 'info', 'password']
 }
})